package com.gugee.ins.data.collector.media.listener;

import com.gugee.ins.data.collector.media.config.InsMediaConfig;
import com.gugee.ins.data.collector.media.service.InsAdMediaIdentifyService;
import com.gugee.ins.data.common.consumer.AbstractGugeeConsumerHandler;
import com.gugee.ins.data.common.msg.InsBloggerMessage;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.kafka.support.Acknowledgment;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 帖子收入监听器
 * @author Huangxin
 */
@Component
@Slf4j
public class InsAdMediaIdentifyListener {
    /**
     * 配置类
     */
    @Autowired
    InsMediaConfig insMediaConfig;

    /**
     * InsAdMediaIdentifyService 服务
     */
    @Autowired
    InsAdMediaIdentifyService insAdMediaIdentifyService;

    private InsAdMediaIdentifyHandler adMediaIdentifyHandler = new InsAdMediaIdentifyHandler();

    /**
     * 监听任务,完成广告帖子识别
     * @param messages
     * @param ack
     */
    @KafkaListener(id="${kafka.consumer.group.insAdMediaIdentify.id}",
            topics = {"${kafka.topics.insAdMediaIdentify.online}","${kafka.topics.insAdMediaIdentify.priority}"},
            containerFactory = "factoryInsAdMediaIdentifyAck")
    public void bloggerMainCollect(List<InsBloggerMessage> messages, Acknowledgment ack) {
        adMediaIdentifyHandler.handle("InsAdMediaIdentify",messages, insMediaConfig.getAcceptInsAdMediaIdentifyMsgTimeMinRange(),ack);
    }

    class InsAdMediaIdentifyHandler extends AbstractGugeeConsumerHandler<InsBloggerMessage> {
        @Override
        public void dealMsg(List<InsBloggerMessage> messages) {
            insAdMediaIdentifyService.handleInsAdMediaIdentify(messages);
        }
    }
}
